	// SelectGroup 选项组
	var SelectGroup=function(selector,options){
		this.selector=selector;
		this.element=$(selector).get(0);
		if(typeof options=="undefined"){
			var dataUrl=$(selector).attr("data-url");
			var options={
				url:dataUrl,
				selectors:[]
			}
			var children=$("select",selector);
			var data=new Object();
			for(var i=0;i<children.length;i++){
				options.selectors.push({selector:children.eq(i),value:children.eq(i).val()})
			}
		}
		this.options=options;
		this.url=options.url;
		this.selectors=options.selectors
		if(typeof(options.optionsFiltration)!="undefined"){
			this.optionsFiltration=options.optionsFiltration;
		}
		
		this.total=this.selectors.length;
	}
	SelectGroup.prototype=new Control();
	SelectGroup.prototype.data=null;
	
	SelectGroup.prototype.init=function(){
		this.selects=new Array();
		this.load(this.options.url)
	}
	SelectGroup.prototype.reset=function(){
		this.loadCompleteHandle(this.data)
	}
	SelectGroup.prototype.optionsFiltration=function(data){
		return data;
	}
	SelectGroup.prototype.load=function(url){
		var self=this;
		url=url;
		var options={
			url: url,
			dataType:"json",
			cache:false,
			success: function(data, textStatus, jqXHR){
				self.loadCompleteHandle(data)
			},
			error :function(){
				//alert("SelectGroup load error ");
			}
		}
		$.ajax(options);
	}
	SelectGroup.prototype.loadCompleteHandle=function(data){
		
		this.data=data;
		this.total=this.options.selectors.length;
		var self=this;
		var select=null;
		var id="";
		var value="";
		var selector="";
		for(var i=0;i<this.total;i++){
			id=this.options.selectors[i].id;
			selector=this.options.selectors[i].selector;
			
			if(typeof selector=="undefined"){
				selector="#"+id
			}
			
			select=new SelectGroup.Select(selector,i,function(num,id){self.selectControl(num,id)})
			select.init();
			this.selects.push(select);
		}
		this.setValues(0,data);
	}
	SelectGroup.prototype.setValues=function(num,data){
		this.selectControl(num,data)
		var value="";
		value=this.options.selectors[num].value;
		if(value!=""){
			this.selects[num].setValue(value);
			if(typeof(data)!="undefined"){
				for(var i=0;i<data.length;i++){
					if(data[i].value==value){
						if(num+1<this.total){
							this.setValues(num+1,data[i].children);
						}
					}
				}
			}
		}
	}
	SelectGroup.prototype.selectControl=function(num,data){
		
		if(this.total<=num){
			return ;
		}
		
		for(var i=0;i<this.total;i++){
			if(i<num){
				this.selects[i].focusOpen();
			}else{
				this.selects[i].focusClose();
			}
		}
		if(typeof(data)!="undefined"){
			var defaultOption=[{
				value:"",
				text:"==请选择=="
			}]
			var childrenData=defaultOption.concat(data);
			childrenData=this.optionsFiltration(childrenData);
			this.selects[num].setData(childrenData);
			this.selects[num].focusOpen();
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//组合框组.选择框
	SelectGroup.Select=function(selector,num,selectControl){
		this.num=num;
		this.element=$(selector).get(0);
		this.selectControl=selectControl;
	}
	SelectGroup.Select.prototype.init=function(){
		var self=this;
		$(this.element).bind("change",function(event){self.changeHandle(event)})
	}
	SelectGroup.Select.prototype.setData=function(data){
		this.data=data;
		var html="";
		var option=null
		
		this.element.length=0;
		for(var i in data){
			option = new Option(data[i].text,data[i].value);    
			this.element.options.add(option);   
		}
	}
	SelectGroup.Select.prototype.getSelectedData=function(value){
		var data=null;
		for(var i in this.data){
			if(this.data[i].value==value){
				data=this.data[i];
				break;
			}
		}
		return data;
	}
	SelectGroup.Select.prototype.changeHandle=function(event){
		var value=event.currentTarget.value;
		var selectedData=this.getSelectedData(value);
		if(selectedData!=null){
			this.selectControl(this.num+1,selectedData.children);
		}
	}
	SelectGroup.Select.prototype.focusOpen=function(){
		$(this.element).show();
	}
	SelectGroup.Select.prototype.focusClose=function(){
		this.setValue("")
		$(this.element).hide();
	}
	SelectGroup.Select.prototype.setValue=function(value){
		if(value==null){
			return ;
		}
		value=value.toString();
		this.setSelected(value);
	}
	SelectGroup.Select.prototype.setSelected=function(value){
		for (var i = 0; i < this.element.options.length; i++) {
			if (this.element.options[i].value == value) {        
				this.element.options[i].selected=true;       
			}        
		} 
	}
	
	
	
	/*
	
	Option
	
	*/
	
	SelectGroup.Select.Option=function(value,text){
		this.value=value;
		this.text=text;
	}
	SelectGroup.Select.Option.prototype.getHtml=function(){
		var html="<option value=\""+this.value+"\">"+this.text+"</option>"
		return html;
	}
	HTMLTurbo.control.SelectGroup=SelectGroup;